/*
 *  This file is part of ZiggyStardust.
 *
 *  ZiggyStardust is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  ZiggyStardust is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.wisc.csvParser.plugins;

/**
 *
 * @author  lawinslow
 */
public class JPanelBuoyancyFrequency extends javax.swing.JPanel {
    
    private DataGeneratorBuoyancyFrequency bf;
    
    
    /** Creates new form JPanelBuoyancyFrequency
     * @param bf BuoyancyFrequencyGenerator Object
     */
    public JPanelBuoyancyFrequency(DataGeneratorBuoyancyFrequency bf) {
        initComponents();
        
        this.bf = bf;
        
        bf.addEventHandler(new DataGeneratorBuoyancyFrequency.IEventHandler(){
            @Override
            public void eventRaised(DataGeneratorBuoyancyFrequency.events e){
                handleEvent(e);
            };
            
        });
                
        
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        waterTempNameTB = new javax.swing.JTextField();
        saveButton = new javax.swing.JButton();
        buoyancyFrequencyNameTB = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        startedCB = new javax.swing.JCheckBox();

        jLabel2.setText("Water Temperature Variable Name (Caps Insensitive)");

        waterTempNameTB.setText("WATER_TEMP");
        waterTempNameTB.setPreferredSize(new java.awt.Dimension(75, 20));

        saveButton.setText("Save");
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });

        buoyancyFrequencyNameTB.setText("Buoyancy Frequency");
        buoyancyFrequencyNameTB.setPreferredSize(new java.awt.Dimension(75, 20));

        jLabel3.setText("Buoyancy Frequency Variable Name");

        startedCB.setText("Started");
        startedCB.setEnabled(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(waterTempNameTB, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 67, Short.MAX_VALUE)
                        .addComponent(startedCB))
                    .addComponent(jLabel3)
                    .addComponent(buoyancyFrequencyNameTB, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(saveButton))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(startedCB)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(waterTempNameTB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(buoyancyFrequencyNameTB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(saveButton)))
                .addContainerGap(169, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        bf.setBuoyancyFrequencyVocab(buoyancyFrequencyNameTB.getText());
        bf.setWaterTempVocab(waterTempNameTB.getText());
}//GEN-LAST:event_saveButtonActionPerformed
    
    private void globalSetEnable(boolean enable){
        saveButton.setEnabled(enable);
        waterTempNameTB.setEnabled(enable);
        buoyancyFrequencyNameTB.setEnabled(enable);
    }
    
    private void updateDisplay(){
        buoyancyFrequencyNameTB.setText(bf.getBuoyancyFrequencyVocab());
        waterTempNameTB.setText(bf.getWaterTempVocab());
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField buoyancyFrequencyNameTB;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JButton saveButton;
    private javax.swing.JCheckBox startedCB;
    private javax.swing.JTextField waterTempNameTB;
    // End of variables declaration//GEN-END:variables
    
    private void handleEvent(DataGeneratorBuoyancyFrequency.events e){
        if(e == DataGeneratorBuoyancyFrequency.events.start){
            globalSetEnable(false);
            startedCB.setSelected(true);
        }else if(e == DataGeneratorBuoyancyFrequency.events.stop){
            globalSetEnable(true);
            startedCB.setSelected(false);
        }else if(e == DataGeneratorBuoyancyFrequency.events.bfgenerated){
            
        }else if(e == DataGeneratorBuoyancyFrequency.events.bfgenerated){
            updateDisplay();
        }
    }
}
